﻿using System.IO;
using System.Xml.Linq;
using Microsoft.Xna.Framework.Content;

namespace SceneManager
{
	/// <summary>
	/// This class will be instantiated by the XNA Framework Content
	/// Pipeline to read the specified data type from binary .xnb format.
	/// 
	/// Unlike the other Content Pipeline support classes, this should
	/// be a part of your main game project, and not the Content Pipeline
	/// Extension Library project.
	/// </summary>
	public class XElementReader : ContentTypeReader<XElement>
	{
		protected override XElement Read(ContentReader input, XElement existingInstance)
		{
			var length = input.ReadInt64();
			var bytes = input.ReadBytes((int)length);
			var stream = new MemoryStream(bytes);
			var reader = new StreamReader(stream);
			var xml = XElement.Load(reader);
			stream.Close();
			return xml;
		}
	}
}